﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Produce.Application.DTO.Input;
using Produce.Application.Services;
using Produce.Domain.Entities;
using Produce.Result;

namespace Produce.Api.Controllers
{
    /// <summary>
    /// 产品锁定/解锁
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProduceStateController : ControllerBase
    {
        private readonly IProduceStateService _service;
        private readonly ILogger<ProduceStateController> _logger;

        public ProduceStateController(IProduceStateService service, ILogger<ProduceStateController> logger)
        {
            _service=service;
            _logger=logger;
        }


        /// <summary>
        /// 产品锁定的列表  （State是false）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public ApiResult<ProductionState> GetProduceStateFalse([FromQuery]GetProduceStateInput input)
        {
            _logger.LogInformation($"进行了产品锁定的操作,在{DateTime.Now}");
            return _service.GetProduceStateFalse(input);
        }

        /// <summary>
        /// 锁定产品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("{id}/{desc}")]
        public ApiResult<int> UpdateTrueState(long id, string desc)
        {
            _logger.LogInformation($"进行了产品锁定的操作,ID:{id},在{DateTime.Now}");
            return _service.UpdateTrueState(id, desc);
        }


        /// <summary>
        /// 删除产品锁定
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut("{id}")]
        public ApiResult<int> DelState(long id)
        {
            _logger.LogInformation($"进行了删除产品锁定的操作,ID:{id},在{DateTime.Now}");
            return _service.DelState(id);
        }

        /// <summary>
        /// 产品解锁的列表  （State是true）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public ApiResult<List<ProductionState>> GetProduceStateTrue([FromQuery]PageInput input)
        {
            _logger.LogInformation($"进行了产品解锁的操作,在{DateTime.Now}");
            return _service.GetProduceStateTrue(input);
        }
        /// <summary>
        /// 解锁产品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut("{id}")]
        public ApiResult<int> UpdateFalseState(long id)
        {
            _logger.LogInformation($"进行了产品解锁的操作,ID:{id},在{DateTime.Now}");
            return _service.UpdateFalseState(id);
        }
    }
}
